package org.spring.springboot.service;


import java.util.List;
import java.util.Map;

@Service
@CacheConfig(cacheNames="index")
public class ActivityService {

    @Autowired
    ActivityDao dao;
		
		    @Cacheable(key="'system_adv_activity'")
    public List<Map<String,Object>> getAdvList(){
        return dao.getAdvList();
    }
	
	    public List<Map<String,Object>> sumActivityInfo(Activity act){
        return  this.dao.sumActivityInfo(act);
    }
	
	    public Map<String,Object> findActivity(Activity activity){
      return  dao.findActivity(activity);
    }
	
	    public List<Map<String,Object>> sumActivityInfo(Activity act){
        return  this.dao.sumActivityInfo(act);
    }
	    public List<Map<String,Object>> provinceList(){
        return  this.dao.provinceList();
    }
    public List<Map<String,Object>> activityList (){
        return this.dao.activityList();
    }
    public List<Map<String,Object>> countActivity(){
        return  this.dao.countActivity();
    }
    public List<Map<String,Object>> countOrg(){
        return  this.dao.countOrg();
    }
	    public Map<String,Object> searchActivityList(Activity act){
        return  this.dao.searchActivityList(act);
    }
	    public Map<String,Object> findActivity(Activity activity){
      return  dao.findActivity(activity);
    }
	    /**
     * 活动详情-成员
     * @return
     */
    @RequestMapping(value = "/activityinfo")
    public String activityInfo(@ModelAttribute("data") Activity a) {
        a.setFinish(0);
        Map<String,Object> map = service.queryActivity(a);
        map.put("current_time",DateUtil.getStringDate());//当前时间
        if(map!=null){
            //用户是否已加入活动
//            int isJoin = service.isJoin(a.getUser_id(),a.getId());
//            map.put("isJoin",isJoin);

            //活动成员
            List<Map<String,Object>> member = service.queryActivityMemberList(a.getId());
            map.put("member",member);
            //抽奖记录
            if(a.getAccount_id()==null){
                a.setAccount_id(0);
            }
            Map<String,Object> lottery = service.getLotteryRecord(a.getId(),a.getAccount_id(),"activity");
            map.put("lottery",lottery);
            //是否开启抽奖
            String is_lottery = systemService.getSystemConfig("is_lottery");
            map.put("is_lottery",is_lottery);
            return JSONValue.toJSONString(new Handle(200, "成功", map));
        }else{
            return JSONValue.toJSONString(new Handle(401, "活动不存在或已结束", map));
        }
    }




	    public List<Map<String, Object>> findActivityInfo(Integer id){
       return this.dao.findActivityInfo(id);
    }
	
	

}
